1. Field of the Invention
The present invention relates to a data storing method, and more specifically, to a bi-directional data storing method for storing data sets selectively from one of two terminals of a memory block.
2. Description of the Prior Art
In general, for storing data sets, there are three primary methods: ordered, unordered, and hashed data-storing methods. The characteristic of the ordered data-storing method is to physically order the data sets stored in a memory. That is, when writing a data set into the memory, the system needs to perform a sorting operation to physically order the data sets stored in the memory. The characteristic of the unordered data-storing method is to write the data sets into the memory according to the time sequence of receiving the data sets. Hence, compared with the ordered data-storing method, when storing a data set, the unordered data-storing method omits a corresponding sorting operation. Because the data sets stored in the memory are not arranged in order conforming to any kind of rule, the system needs to further provide a mapping table to record a starting address and a size of each data set. Therefore, when accessing a specific data set, the system reads the address of the specific data set recorded in the mapping table without sequentially searching the memory for the specific data set. The hashed data-storing method performs a computation operation on each data set by using a hash function, wherein a value generated by the computation operation corresponds to a predetermined memory address. Hence, when accessing the data set, the system only needs to perform a computation operation using the hash function and then the memory address corresponding to the data set can be generated.
These three data-storing methods will be limited when they are applied in a system with a small memory, such as a memory in a mobile phone. Usually, a mobile phone's memory capacity is small. A possible consequence of this is that when utilizing the above-mentioned hashed data-storing method, if the system cannot select an appropriate hash function, a situation in which the memory is wasted may occur. Compared with the hashed data-storing method, the ordered data-storing method can efficiently utilize all of the memory. The disadvantage is that it is necessary to perform the above-mentioned sorting operation when storing each data set, which is a heavy load for the mobile phone, because the mobile phone has less computational abilities. It could therefore be concluded that for the mobile phone, the unordered data-storing method would seem to be an appropriate compromise. The unordered data-storing method writes the data sets into the memory according to the time sequence of receiving the data sets. A disadvantage of this method, however, is that memory spaces allocated and released by any kind of the three above-mentioned data-storing methods will discontinuously exist in the memory and cannot be utilized again. Hence, after a certain period of time, it is necessary to perform a defragmentation operation on the memory in order to combine the above-mentioned discontinuous memory spaces with remaining spaces of the memory, to allow the combined available memory spaces to be allocated for storing other data sets.
Please refer to FIG. 1. FIG. 1 is a diagram of a memory block 10 when utilizing a conventional unordered data-storing method. As shown in FIG. 1, the memory block 10 comprises a plurality of memory spaces 12, 16, 22, 28, 32, and 34 storing data sets D1, D3, D5, D8, D9, and D10 respectively, and a plurality of released memory spaces (parts with oblique lines shown in FIG. 1) 14, 18, 24, and 26, and a never-used memory space 36. When the first data set D1 is received, the memory space 12 of the memory block 10 is arranged to store the data set D1 according to the direction indicated by a pointer 20, and then the memory space 14 of the memory block 10 is arranged to store the data set D2. In the same manner, the data sets D3˜D10 are sequentially and continuously written into the memory block 10. Finally, the memory space 34 is arranged to store the tenth data set D10. After this operation, some data sets (i.e. the data sets D2, D4, D6, D7) may not be utilized by the system, so the system releases the memory spaces 14, 18, 24, 26 (parts with oblique lines shown in FIG. 1) storing the data sets D2, D4, D6, D7. The memory space 36 and the memory spaces 14, 18, 24, 26 can now be arranged to store other data sets, so the system performs a defragmentation operation on the memory block 10 to make the memory spaces 14, 18, 24, 26 be concentrated in the left side of the memory block 10, which means the memory spaces 14, 18, 24, 26 are combined with the memory available space 36. This allows the memory spaces to be more efficiently arranged to store other data sets. The above-mentioned defragmentation operation needs to be performed repeatedly, and each performance takes a significant amount of time, which not only rapidly increases the complexity of tasks executed by the system, but also makes a user feel that the reactions of the system are slow. Therefore, to efficiently utilize memory spaces and reduce the complexity of performing a defragmentation operation on the memory is a major topic of the claimed invention.